package com.zjy.heath_ms.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mysql.jdbc.StringUtils;
import com.zjy.heath_ms.entity.QueryPageBean;
import com.zjy.heath_ms.mapper.CheckGroupMapper;
import com.zjy.heath_ms.pojo.CheckGroup;
import com.zjy.heath_ms.service.CheckGroupService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 项目名 heath_ms
 * 类名  CheckGroupServiceImpl
 * 作者 lzq
 * 创建时间  2025/5/25 12:37
 */

@Service
public class CheckGroupServiceImpl extends ServiceImpl<CheckGroupMapper, CheckGroup> implements CheckGroupService {
    @Override
    public Page<CheckGroup> findPage(QueryPageBean queryPageBean) {
        // 查询条件
        LambdaQueryWrapper<CheckGroup> queryPageBeanLambdaQueryWrapper = new LambdaQueryWrapper<>();
        if (!StringUtils.isNullOrEmpty(queryPageBean.getQueryString())) {
            // 编码
            queryPageBeanLambdaQueryWrapper.like( CheckGroup::getCode, queryPageBean.getQueryString());
            queryPageBeanLambdaQueryWrapper.or();
            // 名称
            queryPageBeanLambdaQueryWrapper.like( CheckGroup::getName, queryPageBean.getQueryString());
            queryPageBeanLambdaQueryWrapper.or();
            // 助记码
            queryPageBeanLambdaQueryWrapper.like( CheckGroup::getHelpCode, queryPageBean.getQueryString());
        }

        // 分页条件
        Page<CheckGroup> queryPageBeanPage = new Page<>(queryPageBean.getCurrentPage(), queryPageBean.getPageSize());
        // 分页查询
        baseMapper.selectPage(queryPageBeanPage, queryPageBeanLambdaQueryWrapper);
        // 返回数据
        return queryPageBeanPage;
    }

    @Override
    public List<CheckGroup> getAll(String queryString) {
        // 查询条件
        LambdaQueryWrapper<CheckGroup> queryPageBeanLambdaQueryWrapper = new LambdaQueryWrapper<>();
        if (!StringUtils.isNullOrEmpty(queryString)) {
            // 编码
            queryPageBeanLambdaQueryWrapper.like( CheckGroup::getCode, queryString);
            queryPageBeanLambdaQueryWrapper.or();
            // 名称
            queryPageBeanLambdaQueryWrapper.like( CheckGroup::getName, queryString);
            queryPageBeanLambdaQueryWrapper.or();
            // 助记码
            queryPageBeanLambdaQueryWrapper.like( CheckGroup::getHelpCode, queryString);
        }
        return baseMapper.selectList(queryPageBeanLambdaQueryWrapper);
    }
}
